/**
 * 
*/
package GUI_SPR;

//Se importa lo necesario
import java.awt.BorderLayout;
import javax.swing.JOptionPane;
import sourceCode.Cuenta;
import sourceCode.StoreProductRegistration;

/**
 * @author edwin
 * @version 1.0
 */
public class MenuOpciones extends javax.swing.JFrame {

    //-----------------------------------------------------------------
    //  Constructor:.
    //-----------------------------------------------------------------
    
    /**
     * Método que permite la creación de un nuevo objeto de Menu.
     */
    public MenuOpciones() {
       
        initComponents();
        //Se coloca el fondo de la ventana.
        Fondo fondo = new Fondo (700,550,"fondo15.jpg");
        this.add(fondo,BorderLayout.CENTER);
        this.pack();
        try {
            this.nombreUsuarioShowL.setText(cuenta.getUsuario());
        }
        catch(Exception e) {
            JOptionPane.showMessageDialog(null, e);
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buscarB = new javax.swing.JButton();
        newB = new javax.swing.JButton();
        tituloPanelL = new javax.swing.JLabel();
        buscarL = new javax.swing.JLabel();
        ingresoL = new javax.swing.JLabel();
        usuarioL = new javax.swing.JLabel();
        usuarioB = new javax.swing.JButton();
        vitualL = new javax.swing.JLabel();
        usuarioShowL = new javax.swing.JLabel();
        nombreUsuarioShowL = new javax.swing.JLabel();
        contraseñaML = new javax.swing.JLabel();
        contraseñaMB = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Menu Principal");
        setResizable(false);

        buscarB.setFont(new java.awt.Font("Bookman Old Style", 0, 11));
        buscarB.setForeground(new java.awt.Color(255, 255, 255));
        buscarB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buscarBActionPerformed(evt);
            }
        });

        newB.setFont(new java.awt.Font("Bookman Old Style", 0, 11));
        newB.setForeground(new java.awt.Color(255, 255, 255));
        newB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newBActionPerformed(evt);
            }
        });

        tituloPanelL.setFont(new java.awt.Font("French Script MT", 0, 36));
        tituloPanelL.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/icon/menu.png"))); // NOI18N

        buscarL.setFont(new java.awt.Font("Eras Demi ITC", 0, 14));
        buscarL.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/icon/search1.png"))); // NOI18N

        ingresoL.setFont(new java.awt.Font("Eras Demi ITC", 0, 14));
        ingresoL.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/icon/new.png"))); // NOI18N

        usuarioL.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/icon/user.png"))); // NOI18N

        usuarioB.setFont(new java.awt.Font("Bookman Old Style", 0, 11));
        usuarioB.setForeground(new java.awt.Color(255, 255, 255));
        usuarioB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                usuarioBActionPerformed(evt);
            }
        });

        vitualL.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/icon/virtual.png"))); // NOI18N

        usuarioShowL.setFont(new java.awt.Font("Bookman Old Style", 0, 11));
        usuarioShowL.setForeground(new java.awt.Color(255, 255, 255));
        usuarioShowL.setText("Usuario: ");

        nombreUsuarioShowL.setFont(new java.awt.Font("Bookman Old Style", 0, 11));
        nombreUsuarioShowL.setForeground(new java.awt.Color(255, 255, 255));
        nombreUsuarioShowL.setText("-----------");

        contraseñaML.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/icon/contraseñaM.png"))); // NOI18N

        contraseñaMB.setFont(new java.awt.Font("Bookman Old Style", 0, 11));
        contraseñaMB.setForeground(new java.awt.Color(255, 255, 255));
        contraseñaMB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                contraseñaMBActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(tituloPanelL)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(usuarioL)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(contraseñaML)
                                .addGap(18, 18, 18)
                                .addComponent(contraseñaMB, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(usuarioB, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(vitualL)
                                .addGap(127, 127, 127))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(usuarioShowL)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(nombreUsuarioShowL)
                                .addGap(58, 58, 58))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(buscarL)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(buscarB, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(ingresoL)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(newB, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(13, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(tituloPanelL)
                        .addGap(38, 38, 38)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(45, 45, 45)
                                .addComponent(usuarioB, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(20, 20, 20)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(usuarioL)
                                        .addGap(26, 26, 26))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(44, 44, 44)
                                                .addComponent(buscarB, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addComponent(buscarL))
                                        .addGap(18, 18, 18)))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(ingresoL)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(contraseñaML)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(29, 29, 29)
                                                .addComponent(contraseñaMB, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(40, 40, 40)
                                        .addComponent(newB, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addGap(26, 26, 26))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(usuarioShowL)
                            .addComponent(nombreUsuarioShowL))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(vitualL)
                        .addGap(380, 380, 380)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    //------------------------------------------------------------------------
    //Métodos 
    //------------------------------------------------------------------------    
    
    /**
     * Guarda la cuenta con la que se estara trabajando
     * @param cuentaX
     */
    public static void setCuenta(Cuenta cuentaX){
        cuenta = cuentaX;
    }
    
    /**
     * Regresa la cartera con la cual se trabaja
     * @return
     */
    public static Cuenta getCuenta(){
        return cuenta;
    }
    
    
    
    /**
     * Método que permite Agregar una nueva categoria al registro.
     * @param evt 
     */
    private void newBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newBActionPerformed
        
        MenuIngreso.setCuenta(StoreProductRegistration.getCuenta(cuenta.getUsuario(), cuenta.getContraseñaMaestra())); 
        MenuIngreso categoria = new MenuIngreso();
        
        categoria.setTitulo("new.png");
        categoria.show();
        dispose();
        
    }//GEN-LAST:event_newBActionPerformed

    /**
     * Método que permite cambiar el usuario que se está utilizando.
     * @param evt El evento que se da al presionar el botón.
     */
    private void usuarioBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_usuarioBActionPerformed
        MenuPrincipal usuario = new MenuPrincipal();
        usuario.show();
        dispose();
    }//GEN-LAST:event_usuarioBActionPerformed

    /**
     * Método que permite buscar la información de alguna categoria.
     * @param evt el evento que se da al presionar el botón.
     */
    private void buscarBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscarBActionPerformed
       
        Busqueda.setCuenta(StoreProductRegistration.getCuenta(cuenta.getUsuario(), cuenta.getContraseñaMaestra())); 
        Busqueda categoria = new Busqueda();
        //categoria.setTitulo("search1.png");
        //categoria.setSeleccion(false);
        categoria.show();
        dispose();
    }//GEN-LAST:event_buscarBActionPerformed

   
    /**
     * Método que permite cambiar la contraseña del usuario.
     * @param evt El evento que se da al presionar el botón
     */
    private void contraseñaMBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_contraseñaMBActionPerformed
        String contraseña = "";
            try{
                do{
                    //Lanza un mensaje que le permite ingresar la contraseña maestra
                    contraseña =JOptionPane.showInputDialog("Ingrese la contraseña maestra");
                    //Verifica que el usuario no cancele la opción
                    try{
                        if (contraseña.equals(JOptionPane.CANCEL_OPTION)==false){
                            //verifica que exista esa contraseña
                            
                        }
                    }catch(Exception e){}
                }while (contraseña.equals("")==true);  
            }catch(Exception e){}
    }//GEN-LAST:event_contraseñaMBActionPerformed

    /**
     * Método para manejar la clase
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MenuOpciones().setVisible(true);
            }
        });
    }
    
    //------------------------------------------------------------------------
    //Atributos
    //------------------------------------------------------------------------
    private static Cuenta cuenta;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buscarB;
    private javax.swing.JLabel buscarL;
    private javax.swing.JButton contraseñaMB;
    private javax.swing.JLabel contraseñaML;
    private javax.swing.JLabel ingresoL;
    private javax.swing.JButton newB;
    private javax.swing.JLabel nombreUsuarioShowL;
    private javax.swing.JLabel tituloPanelL;
    private javax.swing.JButton usuarioB;
    private javax.swing.JLabel usuarioL;
    private javax.swing.JLabel usuarioShowL;
    private javax.swing.JLabel vitualL;
    // End of variables declaration//GEN-END:variables
}
